#!/usr/bin/env node

const fs = require('fs')
const file = '../package-lock.json'

const result = JSON.parse(fs.readFileSync(file))

const pg = '../package.json'
const pgResult = JSON.parse(fs.readFileSync(pg))
const pgDependencies = pgResult.dependencies
const pgDevDependencies = pgResult.devDependencies
var pgDic = {}

for (const key in pgDependencies) {
  const value = pgDependencies[key] || 'unkonw'
  pgDic[key] = value
}

pgDic['     ~~~~~~~~~~~~~~~~~这个是分界线~~~~~~~~~~~~~~~~~'] =
  '~~~~~~~~~~~~~~~~~'

for (const key in pgDevDependencies) {
  const value = pgDevDependencies[key] || 'unkonw'
  pgDic[key] = value
}

const dic = result.dependencies

console.log('')
console.log(
  '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-',
)
console.log('下面开始打印 左边是' + pg + ' ，右边是' + file + ' 中使用的版本:')
for (const key in pgDic) {
  const pgValue = pgDic[key] || 'unkonw'
  const item = dic[key] || {}
  const version = item.version || 'unkonw'

  console.log('  ' + key + ': ' + pgValue + '____lock: ' + version)
}
console.log(
  '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-',
)
console.log('')
